<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<title>Insert title here</title>
<script type="text/javascript">
	function fun1() {
		//一对{}表示json对象,key:value
		var obj = {
			"state" : 10086
		};
		alert(obj.state);
	}
	function fun2() {
		//多个key-value,中间用,分开
		var obj = {
			"state" : 0,
			"message" : "失败"
		};
		alert(obj.state + "," + obj.message);
	}
	function fun3() {

		var obj = {
			"state" : 1,
			"message" : "成功",
			"data" : {
				"name" : "朱小明",
				"age" : "16"
			}
		};
		alert(obj.data.name + "," + obj.data.age);

	}

	function fun4() {
		//[]表数组
		var obj = [ {
			"code" : 11,
			"name" : "成都"
		}, {
			"code" : 12,
			"name" : "广安"
		} ];
		for (var i = 0; i < obj.length; i++) {
			alert(obj[i].code + "," + obj[i].name);
		}
	}
	function fun5() {

		var obj = {
			"state" : 1,
			"message" : "成功",
			"data" : [
			          {"code" : 11,"name" : "成都"},
			          {"code" : 12,"name" : "广安"}
			          ]
		};
		
		for (var i = 0; i < obj.data.length; i++) {
			alert(obj.data[i].code + "," + obj.data[i].name);
		}

	}
</script>
</head>
<body>
	<h1>json的基本语法</h1>
	<a href="#" onclick="fun1()">1个K-V的json定义和访问</a>
	<br>
	<a href="#" onclick="fun2()">多个K-V的json定义和访问</a>
	<br>
	<a href="#" onclick="fun3()">多个K-V的json定义和访问(value为对象)</a>
	<br>
	<a href="#" onclick="fun4()">json数组的定义和访问</a>
	<br>
	<a href="#" onclick="fun5()">多个K-V的json定义和访问(value为数组)</a>
	<br>

</body>
</html>